//Neal Whitworth
//Class: Main.cpp
//This is a dummy driver class to test all of the functionality of the Class object, and the file IO
//Coded by Neal Whitworth

#include "Class.h"  
#include <string>  
#include <iostream>  
#include <fstream> 
#include <array>
#include <istream>

using namespace std;
using namespace ClassNamespace;

//max amount of characters per line 
const int MAXLINE = 256;
const int MAXCLASSES = 1000;

int main(){
	//begin testing of each method of the Class object
	Class *classArray[MAXCLASSES];
	int freeArrayIndex = 0;
	bool overlaps;
	Class *class1 = new Class("bouvier", 1000, 1100, "Cs", "001", "1020", "EB", 140, "MWF");
	cout << class1->toString();
	Class *class2 = new Class("White", 1200, 1300, "CS", "002", "2020", "EB", 325, "TR");
	cout << class2->toString();
	Class *class3 = new Class("Bouvier", 1000, 1500, "CS", "001", "2030", "EB", 312, "MW");
	overlaps = class2->Overlaps(class3);
	cout << overlaps;
	cout << "\n";
	overlaps = class1->Overlaps(class3);
	cout << overlaps;
	cout << "\n";

	//begin file IO 
	//the input file 
	std::ifstream inputFile("TestFile.txt");
	//the max array size = 256 
	char oneline[MAXLINE];
	//the character to split the line at 
	char delimit = ',';
	string values[100];

	//placeholders for the variables
	string nameHolder;
	int start = 0;
	int end = 0;
	string department;
	string section;
	string room;
	string building;
	int course = 0;
	string days;

	//the placeholder for the spot in the file you are at
	int placeHolder = 0;
	//the while loop for the entire file
	while (inputFile){


		/*
		TODO
		implement better way than if/else tree for choosing which portion to instantiate
		*/
		inputFile.getline(oneline, MAXLINE, delimit);
		if (placeHolder == 0){
			nameHolder = oneline;
			placeHolder++;
		}
		else if (placeHolder == 1){
			start = atoi(oneline);
			placeHolder++;
		}
		else if (placeHolder == 2){
			end = atoi(oneline);
			placeHolder++;
		}
		else if (placeHolder == 3){
			department = oneline;
			placeHolder++;
		}
		else if (placeHolder == 4){
			section = oneline;
			placeHolder++;
		}
		else if (placeHolder == 5){
			room = oneline;
			placeHolder++;
		}
		else if (placeHolder == 6){
			building = oneline;
			placeHolder++;
		}
		else if (placeHolder == 7){
			course = atoi(oneline);
			placeHolder++;
		}
		else if (placeHolder == 8){
			days = oneline;
			placeHolder++;
		}
		else{
			//create class object, gets the next line, and sets the instructors name as well as resets the placeholder variable
			classArray[freeArrayIndex] = new Class(nameHolder, start, end, department, section, room, building, course, days);
			freeArrayIndex++;
			nameHolder = oneline;
			placeHolder = 1;
		}


	}

	//outputs all of the class objects in the array of classes
	for (int i = 0; i < freeArrayIndex; i++){
		if (classArray[i] != nullptr){
			cout << classArray[i]->toString();
		}
	}


}